home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 12677 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.7 KB  |  107 lines

  1. Path: news.ucdavis.edu!usenet
  2. From: ez055808@peseta.ucdavis.edu (Bill Clark)
  3. Newsgroups: comp.lang.c++
  4. Subject: Problem w/ VC 4.1 and the Deadly Diamond
  5. Date: 21 Mar 1996 04:38:37 GMT
  6. Organization: Huh?
  7. Message-ID: <4iqmgd$fuk@mark.ucdavis.edu>
  8. NNTP-Posting-Host: reqf-090.ucdavis.edu
  9. Mime-Version: 1.0
  10. Content-Type: Text/Plain; charset=US-ASCII
  11. X-Newsreader: WinVN 0.99.7
  12.  
  13. The following code doesn't compile under VC 4.1 (or 4.0) (I haven't tried it 
  14. yet with other compilers):
  15.  
  16. ---------------------------------------------------------------
  17. class A
  18. {
  19. public:
  20.   A() { }
  21.   virtual ~A() { }
  22. };
  23.  
  24. class B: virtual public A
  25. {
  26. public:
  27.   B();
  28.   virtual ~B() { }
  29. };
  30.  
  31. B::B(): A()
  32. {
  33. }
  34.  
  35. class C: virtual public A
  36. {
  37. public:
  38.   C();
  39.   virtual ~C() { }
  40. };
  41.  
  42. C::C(): A()
  43. {
  44. }
  45.  
  46. class D: public B, public C
  47. {
  48. public:
  49.   D();
  50.   virtual ~D() { }
  51. };
  52.  
  53. D::D(): B(), C()
  54. {
  55. }
  56.  
  57.  
  58. class TestClass: public D
  59. {
  60. public:
  61.   TestClass();
  62.   virtual ~TestClass() { }
  63. };
  64.  
  65. TestClass::TestClass(): D()
  66. {
  67. }
  68.  
  69.  
  70. void
  71. testFunc1(const TestClass t)
  72. {
  73. }
  74.  
  75. void
  76. testFunc2()
  77. {
  78.   TestClass t;
  79.   testFunc1(t);
  80. }
  81.  
  82. void
  83. main(void)
  84. {
  85.   testFunc2();
  86. }
  87.  
  88. ------------------------------------------------------------------
  89. The call to testFunc1() gives the following error message:
  90.  
  91. error C2662: '__vbaseDtor' : cannot convert 'this' pointer from 'const class
  92. TestClass *' to 'class TestClass *const '
  93.  
  94. If I change the parameter in testFunc1() to a ref, i.e. const TestClass& t, 
  95. then it compiles fine.
  96.  
  97. Of course, it should be passed by reference; but I don't understand why I'm 
  98. getting this error. If I un-virtual the inheritance of B and C from A (thus 
  99. avoiding the deadly diamond, but causing other headaches), then no compiler 
  100. error. 
  101.  
  102. What gives???
  103.  
  104. Thanks,
  105. Bill Clark
  106.  
  107.